angular.module('starter', ['ionic', 'route', 'config', 'global', 'ngCordova'])

    .run(function ($ionicPlatform, $http, $rootScope, $ionicPlatform, $location, $ionicLoading, $ionicPopup, $ionicHistory, $ionicViewSwitcher) {
        $ionicPlatform.ready(function () {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                cordova.plugins.Keyboard.disableScroll(true);
            }
            if (window.StatusBar) {
                // org.apache.cordova.statusbar required
                StatusBar.styleDefault();
            }
        });


        //主页面显示退出提示框
        $ionicPlatform.registerBackButtonAction(function (e) {
            e.preventDefault();

            function showConfirm() {
                var confirmPopup = $ionicPopup.confirm({
                    title: '<strong>退出应用?</strong>',
                    template: '你确定要退出应用吗?',
                    okText: '退出',
                    okType:"button-assertive",
                    cancelText: '取消'
                });
                confirmPopup.then(function (res) {
                    if (res) {
                        ionic.Platform.exitApp();
                    } else {
                        // Don't close
                    }
                });
            }

            // Is there a page to go back to?
            if ($location.path() == '/tab/home') {
                showConfirm();
            } else if ($ionicHistory.backView()) {
                // Go back in history
                $ionicHistory.goBack();
                $ionicViewSwitcher.nextDirection("back");
            } else {
                // This is the last page: Show confirmation popup
                showConfirm();
            }
            return false;
        }, 101);


        //配置底层域名
        $rootScope.myglobal = {
            serverHost: "http://192.168.50.168:8080/JMCC",
            serverurl: "http://192.168.50.168:8080/JMCC",
            appName: "公务宝",
            appVersionStyle: "android",
            appVersionCode: 1,
            appVersionName: "1.00",
            appVersionDetail: "演示版",
            appUpdateTime: "2017年04月20日"
        }
        $rootScope.jsonerror = "数据获取失败，请检查网络或联系客服。";
        $rootScope.post = function (obj) {
            var str = [];
            for (var p in obj) {
                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            }
            return str.join("&");
        }
        //账户明细列表
        $rootScope.detailaccountinfo = {};
        //对方账户号
        $rootScope.toAccountinfo = [];
        //对方账户名称
        $rootScope.toAccountNameinfo = [];
        $rootScope.businessname = "";

        //approve页面使用
        $rootScope.whatstates = {};

    })


    //隐藏指定tab栏
    .directive('hideTabs', function ($rootScope) {
        return {
            restrict: 'AE',
            link: function ($scope) {
                $rootScope.hideTabs = 'tabs-item-hide';
                //删除这里
                /*$scope.$on('$destroy',function(){
                 $rootScope.hideTabs = ' ';
                 })*/
            }
        }
    })

//定义显示tab的showTabs指令
    .directive("showTabs", function ($rootScope) {
        return {
            restrict: 'AE',
            link: function ($scope) {
                $rootScope.hideTabs = '';


            }
        }
    })




